<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    <div class="container-div">
    <div class="row">
    	<div class="col-sm-12 search-collapse">
				<form id="baseInfo-form">
					<div class="select-list">
						<ul>
							<li>
								姓名：<input type="text" name="empNm"/>
							</li>
							<li>
								证件号码：<input type="text" name="empId"/>
							</li>
							<li>
								公司名称：<input type="text" name="empComp"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="pm:baseInfo:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="pm:baseInfo:edit">
		            <i class="fa fa-edit"></i> 修改
		        </a>
				<a class="btn btn-danger btn-del disabled" onclick="removeEmp()" shiro:hasPermission="pm:baseInfo:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="updateEduInfo()" >
		            <i class="fa fa-edit"></i> 教育经历
		        </a>
		        <a class="btn btn-primary btn-edit disabled" onclick="updateWorkInfo()" >
		            <i class="fa fa-list-ul"></i> 工作经历
		        </a>
		        <a class="btn btn-primary btn-edit disabled" onclick="updateProjInfo()">
		            <i class="fa fa-list-ul"></i> 项目经历
		        </a>
		        <a class="btn btn-primary btn-edit disabled" onclick="updateFileInfo()">
		            <i class="fa fa-list-ul"></i> 附件信息
		        </a>
			    </a>
				<a class="btn btn-warning btn-del disabled" onclick="expResuByEmpIds()" >
			            <i class="fa fa-download"></i> 生成简历
			    </a>
			    <a class="btn btn-success" onclick="batchImport()" >
			            <i class="fa fa-cloud-upload"></i> 批量导入
			    </a>
			    <a class="btn btn-success" onclick="downloadTemplate()" >
			            <i class="fa fa-download"></i> 下载模板
			    </a>
				<a class="btn btn-success" onclick="batchImportAttrImg()" >
					<i class="fa fa-download"></i> 批量导入附件
				</a>
				<a class="btn btn-success" onclick="batchImportProject()" >
					<i class="fa fa-download"></i> 批量导入项目经历
				</a>
			</div>
			 <form class="form-inline">
			     		
			    </form>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
    </div>
    <div th:include="include :: footer"></div>
    <!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" 
						aria-hidden="true">×
				</button>
				<h4 class="modal-title" id="myModalLabel">
					批量导入
				</h4>
			</div>
			<div class="modal-body">
				<input id="excelFile" name="excelFile" type="file" class="file" data-show-preview="false">
				<div class="text-center">
					 <button type="button" id="batchSubmit" class="btn btn-primary">批量导入</button>
			  		 <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				</div>
			  
			</div>
			
		</div>
	</div>
</div>
<div class="modal fade" id="myModalImg" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
	<div class="modal-content">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">×
			</button>
			<h4 class="modal-title" id="myModalLabel">
				批量导入
			</h4>
		</div>
		<div class="modal-body">
			<input id="imgFile" name="imgFile" type="file" class="file" data-show-preview="false">
			<div class="text-center">
				<button type="button" id="batchSubmitImg" class="btn btn-primary">批量导入</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
</div>
<div class="modal fade" id="myModalProject" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">×
				</button>
				<h4 class="modal-title" id="myModalLabel">
					批量导入
				</h4>
			</div>
			<div class="modal-body">
				<input id="projectExcelFile" name="projectExcelFile" type="file" class="file"
					   data-show-preview="false">
				<div class="text-center">
					<button type="button" id="batchSubmitProject" class="btn btn-primary">批量导入</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>
	</div>
</div>
    <script th:inline="javascript">
        var detailFlag = [[${@permission.hasPermi('pm:baseInfo:detail')}]];
        var prefix = ctx + "pm/baseInfo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                detailUrl: prefix + "/detail/{id}",
                exportUrl: prefix + "/export",
                downloadTemplate:prefix + "/template",
                modalName: "人员基本",
                uniqueId:"empId",
                search:false,
                showSearch:false,
                showColumns:false,
                showToggle:false,
                showExport:false,
                showRefresh:false,
                columns: [{
		            checkbox: true
		        },
		        {
					field : 'empId', 
					title : '证件号码'
				},
				{
					field : 'empIdType', 
					title : '证件类型'
				},
				{
					field : 'empNm', 
					title : '姓名'
				},
				{
					field : 'empSex', 
					title : '性别'
				},
				{
					field : 'empTel', 
					title : '手机号码'
				},
				{
					field : 'empComp', 
					title : '所属公司名称'
				},
				{
					field : 'empWorkYears', 
					title : '工作年限'
				},
                {
                    field : 'empVerifyStatus',
                    title : '审核状态',
                    visible: false
                },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="#" onclick="$.operate.detail(\'' + row.empId + '\')"><i class="fa fa-search"></i>详细</a> ');
		            	if(row.empVerifyStatus === '0') {
                            actions.push('<a class="btn btn-success btn-xs" href="#" onclick="verify(\'' + row.empId + '\', \'' + 1 + '\', \'' + row.empNm + '\')"><i class="fa fa-edit"></i>已审核</a>');
                        } else {
                            actions.push('<a class="btn btn-danger btn-xs" href="#" onclick="verify(\'' + row.empId + '\', \'' + 0 + '\', \'' + row.empNm + '\')"><i class="fa fa-remove"></i>未审核</a> ');
                        }
		            	return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
        
        // 更新人员教育经历
        function updateEduInfo(){
 		    var row = $('#bootstrap-table').bootstrapTable('getSelections')[0];
 		    var url = ctx + "pm/baseInfo/upEdu/" + row.empId;
 		   	//$.modal.open("教育经历", url);
 		    createMenuItem(url, "教育经历");
        }
        
     	// 更新人员工作经历
        function updateWorkInfo(){
        	var row = $('#bootstrap-table').bootstrapTable('getSelections')[0];
 		    var url = ctx + "pm/baseInfo/upWork/" + row.empId;
 		    createMenuItem(url, "工作经历");
        }
     	
     	// 更新人员项目经历
        function updateProjInfo(){
        	var row = $('#bootstrap-table').bootstrapTable('getSelections')[0];
 		    var url = ctx + "pm/baseInfo/upProj/" + row.empId;
 		    createMenuItem(url, "项目经历");
        }
     	
     	// 更新人员附件信息
        function updateFileInfo(){
        	var row = $('#bootstrap-table').bootstrapTable('getSelections')[0];
        	var url = ctx + "pm/baseInfo/upFile/" + row.empId;
 		    createMenuItem(url, "附件信息");
        }
     	
     	// 生成人员简历
        function expResuByEmpIds(){
        	var rows = $.map($('#bootstrap-table').bootstrapTable('getSelections'), function (row) { return row["empId"];});
        	var data = { "ids": rows.join()};
			$.modal.loading("正在导出数据，请稍后...");
			$.post(prefix + "/expResuByEmpIds", data, function(result) {
				if (result.code == web_status.SUCCESS) {
			        window.location.href = ctx + "common/download?fileName=" + result.msg + "&delete=" + false;
				} else {
					$.modal.alertError(result.msg);
				}
				$.modal.closeLoading();
			});
        }
     	
     	function expBaseInfo(formId){
     		var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
			$.modal.loading("正在导出数据，请稍后...");
			$.post($.table._option.exportUrl, $("#" + currentId).serializeArray(), function(result) {
				if (result.code == web_status.SUCCESS) {
			        window.location.href = ctx + "common/download?fileName=" + result.msg + "&delete=" + true;
				} else {
					$.modal.alertError(result.msg);
				}
				$.modal.closeLoading();
			});
     	}
     	
     // 批量导入
		function batchImport(){
			$('#excelFile').fileinput('clear');
			$('#myModal').modal('show');
		}

    //初始化fileinput控件（第一次初始化）
  	function initFileInput(ctrlName, uploadUrl) { 
   		var control = $('#' + ctrlName);
   		control.fileinput({
   	   	 	     language: 'zh',
   		         uploadUrl: uploadUrl, //上传的地址
   		         showPreview: false,
   		         allowedFileExtensions : ['xlsx', 'xls'],//接收的文件后缀
   		         minFileCount: 1,                                        // 最小上传数量
   		         maxFileCount: 1,                                        // 最大上传数量
   		         showUpload: false, //是否显示上传按钮
   		         showCaption: true,//是否显示标题
   		         showRemove:false,                                       // 显示移除按钮
   		         uploadClass:"btn btn-success",                        // 上传按钮样式
   		         browseClass: "btn btn-primary", //按钮样式
   		         autoReplace:true,
   		         //enctype: 'multipart/form-data',
   		         previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"
   		         
   	   })
      }
    initFileInput("excelFile", ctx + "pm/import/baseinfo");
    
	$('#batchSubmit').on('click',function(){
		$.modal.confirm("你确定要上传 ?", function() {
			  $('#excelFile').fileinput('upload');
		});
    	
    })
    
	//  uploadAsync设置为true并且已触发批量上传时被触发
	$("#excelFile").on("fileuploaded", function(event,data,previewid,index) {
		var result = data.response;
		if (result.code == '0') {
        	$.modal.msgSuccess("批量导入成功");
    		$.table.refresh();
    		$('#myModal').modal('hide');
        } else {
        	layer.alert(result.msg, {
    	        icon: 0,
    	        area:['60%','90%'],
    	        title: "系统提示",
    	    }, function (index) {
    	    	layer.close(index);
    	    	$('#myModal').modal('hide');
    	    });
        }
    	$.modal.closeLoading();
	 });
	
	$("#excelFile").on('fileerror', function(event, data, msg) {
		$.modal.alertError("批量导入成功失败"+msg);
	});

	function batchImportAttrImg(){
		//      	 批量导入
		$('#imgFile').fileinput('clear');
		$('#myModalImg').modal('show');
	}

        //初始化fileinput控件（第一次初始化）
        function initFileInputImg(ctrlName, uploadUrl) {
            var control = $('#' + ctrlName);
            control.fileinput({
                language: 'zh',
                uploadUrl: uploadUrl, //上传的地址
                showPreview: false,
                allowedFileExtensions : ['zip', 'ZIP'],//接收的文件后缀
                minFileCount: 1,                                        // 最小上传数量
                maxFileCount: 1,                                        // 最大上传数量
                showUpload: false, //是否显示上传按钮
                showCaption: true,//是否显示标题
                showRemove:false,                                       // 显示移除按钮
                uploadClass:"btn btn-success",                        // 上传按钮样式
                browseClass: "btn btn-primary", //按钮样式
                autoReplace:true,
                //enctype: 'multipart/form-data',
                previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"
            })
        }
        initFileInputImg("imgFile", ctx + "pm/import/attrinfo");

        $('#batchSubmitImg').on('click',function(){
            $.modal.confirm("你确定要上传 ?", function() {
                $('#imgFile').fileinput('upload');
            });
        })


        $("#imgFile").on("fileuploaded", function(event,data,previewid,index) {
            var result = data.response;
            if (result.code == '0') {
                $.modal.msgSuccess("批量导入成功");
                $.table.refresh();
                $('#myModalImg').modal('hide');
            } else {
                layer.alert(result.msg, {
                    icon: 0,
                    area:['60%','90%'],
                    title: "系统提示",
                }, function (index) {
                    layer.close(index);
                    $('#myModalImg').modal('hide');
                });
            }
            $.modal.closeLoading();
        });

		// 批量导入项目经历
		function batchImportProject() {
			$('#projectExcelFile').fileinput('clear');
			$('#myModalProject').modal('show');
		}

		//初始化fileinput控件（第一次初始化）
		function initFileInputProject(ctrlName, uploadUrl) {
			var control = $('#' + ctrlName);
			control.fileinput({
				language: 'zh',
				uploadUrl: uploadUrl, //上传的地址
				showPreview: false,
				allowedFileExtensions: ['xlsx', 'xls'],//接收的文件后缀
				minFileCount: 1,                                        // 最小上传数量
				maxFileCount: 1,                                        // 最大上传数量
				showUpload: false, //是否显示上传按钮
				showCaption: true,//是否显示标题
				showRemove: false,                                       // 显示移除按钮
				uploadClass: "btn btn-success",                        // 上传按钮样式
				browseClass: "btn btn-primary", //按钮样式
				autoReplace: true,
				//enctype: 'multipart/form-data',
				previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"
			})
		}

		initFileInputProject("projectExcelFile", ctx + "pm/import/projectinfo");

		$('#batchSubmitProject').on('click', function () {
			$.modal.confirm("你确定要上传 ?", function () {
				$('#projectExcelFile').fileinput('upload');
			});
		})


		$("#projectExcelFile").on("fileuploaded", function (event, data, previewid, index) {
			var result = data.response;
			if (result.code == '0') {
				$.modal.msgSuccess("批量导入成功");
				$.table.refresh();
				$('#myModalProject').modal('hide');
			} else {
				layer.alert(result.msg, {
					icon: 0,
					area: ['60%', '90%'],
					title: "系统提示",
				}, function (index) {
					layer.close(index);
					$('#myModalProject').modal('hide');
				});
			}
			$.modal.closeLoading();
		});

	// 删除人员基本信息，同时删除教育经历、工作经历、项目经历、附件信息。
	function removeEmp(){
		var rows = $.map($('#bootstrap-table').bootstrapTable('getSelections'), function (row) { return row["empId"];});
		if (rows.length == 0) {
			$.modal.alertWarning("请至少选择一条记录");
			return;
		}
		$.modal.confirm("确认要删除选中的" + rows.length + "个人员的所有信息（包括教育经历、工作经历、项目经历、附件信息等）吗?", function() {
			$.operate.submit(prefix + "/remove", "post", "json", {"ids": rows.join()});
		});
	}
	
	function downloadTemplate(){
		$.modal.loading("正在下载模板，请稍后...");
		$.post($.table._option.downloadTemplate, '', function(result) {
			if (result.code == web_status.SUCCESS) {
		        window.location.href = ctx + "common/download?fileName=" + result.msg + "&delete=" + true;
			} else {
				$.modal.alertError(result.msg);
			}
			$.modal.closeLoading();
		});
	}

    function verify(empId, status, empName) {
	    var msg = "";
	    if (status === "0") {
            msg = empName + " 将被审核通过"
        } else{
            msg = empName + " 不被审核通过"
        }
        $.modal.confirm(msg, function() {
            $.operate.submit(prefix + "/verify", "post", "json", {"id": empId, "status": status});
            $.table.refresh();
        })
    }
    </script>
</body>
</html>